home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / bb / src / parmode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-01  |  3.6 KB  |  169 lines

  1. /*
  2.  
  3.         parent mode text array make
  4.  
  5.                       1993.6.27 v1.0
  6.                       copyright Y.Ouchi
  7.  
  8.             input    *intext   : log analize result
  9.                     *disptext : display text array
  10.  
  11.             output    same as input
  12.  
  13. */
  14.  
  15. #include    <string.h>
  16. #include    <stdlib.h>
  17. #include    "bb.h"
  18.  
  19.     /* 関数プロトタイプ宣言 */
  20. void    parset(struct logcontent *, int, int, short *);
  21.  
  22. extern    int        max_textp;
  23.  
  24. static    int        textp;
  25. static    int        comlevel;
  26.  
  27. void    parmode(struct logcontent *intext,short *disptext)
  28. {
  29.     int        i,j,leng,nextp;
  30.     int        startp=0;
  31.     int        nowtext;
  32.     int        startdsp;
  33.     char    nowtitle[8];
  34.     int        nowmesno;
  35.     char    *workp;
  36.     int        textflag;
  37.  
  38.     textflag=0;
  39.     nowtitle[0]=0x00;
  40.     nowmesno=0;
  41.     comlevel=0;
  42.     textp=0;
  43.     nextp=0;
  44.     while (nextp<intext->maxtext){
  45.         for (i=nextp;i<intext->maxtext;i++){
  46.             if (intext->text[i].text.id==TITLE_ID){
  47.                 workp=&intext->text[i].title.a;
  48.                 for (j=0;j<8;j++) nowtitle[j]=workp[j];
  49.                 nowmesno=intext->text[i].title.mes_no;
  50.                 disptext[textp++]=i;
  51.             }
  52.             else{
  53.                 if (intext->text[i].text.id==NOTITLE_TEXT_ID){
  54.                     disptext[textp++]=i;
  55.                 }
  56.                 else{
  57.                     startp=i;
  58.                     textflag=1;
  59.                     break;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         if (textflag==0) break;        /* if no text -- break  1994.2.15 */
  65.         startdsp=textp;
  66.         leng=1;
  67.         for (i=startp+1;i<intext->maxtext;i++){
  68.             if (intext->text[i].title.id==TITLE_ID){
  69.                 if (strcmp(nowtitle,&intext->text[i].title.a)!=0
  70.                         || intext->text[i].title.mes_no!=nowmesno){
  71.                     workp=&intext->text[i].title.a;
  72.                     for (j=0;j<8;j++) nowtitle[j]=workp[j];
  73.                     nowmesno=intext->text[i].title.mes_no;
  74.                     break;
  75.                 }
  76.                 else disptext[textp++]=i;
  77.             }
  78.             leng=leng+1;
  79.         }
  80.         nextp=startp+leng;
  81.  
  82.         nowtext=0;
  83.         while ( nowtext<leng ){
  84.             switch (intext->text[startp+nowtext].text.id){
  85.                 case TITLE_ID :
  86.                     break;
  87.                 case NOTITLE_TEXT_ID :
  88.                     disptext[textp++]=startp+nowtext;
  89.                     break;
  90.                 default :
  91.                     if (intext->text[startp+nowtext].text.com_lvl==0){
  92.                         parset(intext,startp+nowtext,leng-nowtext,disptext);
  93.                     }
  94.                     break;
  95.             }
  96.             nowtext=nowtext+1;
  97.         }
  98.  
  99.         nowtext=startdsp+leng-1;
  100.         while ( nowtext>startdsp ){
  101.             if (intext->text[disptext[nowtext]].text.id==TEXT3C_ID
  102.                     || intext->text[disptext[nowtext]].text.id==TEXT5C_ID){
  103.                 if (abs(intext->text[disptext[nowtext]].text.com_lvl)>0){
  104.                     for (i=nowtext-1;i>startp;i--){
  105.                         if (abs(intext->text[disptext[i]].text.com_lvl) <
  106.                             abs(intext->text[disptext[nowtext]].text.com_lvl)){
  107.                             break;
  108.                         }
  109.                         else{
  110.                             if (abs(intext->text[disptext[i]].text.com_lvl) ==
  111.                                 abs(intext->
  112.                                         text[disptext[nowtext]].text.com_lvl))
  113.                                 intext->text[disptext[i]].text.com_lvl=
  114.                                     abs(intext->text[disptext[i]].text.com_lvl)
  115.                                     *(-1);
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.             nowtext=nowtext-1;
  121.         }
  122.  
  123.     }
  124.  
  125.     max_textp=textp;
  126.  
  127.     return;
  128. }
  129.  
  130. /*
  131.         parent text set (recursive call)
  132.                       1993.6.09 v.00
  133.                       copyright Y.Ouchi
  134.  
  135.             input        text
  136.                         text number
  137.                         length
  138.             output        nothing
  139.  
  140. */
  141.  
  142. void parset(struct logcontent *intext, int sp, int len, short *dispt)
  143. {
  144.     int        i,textnosave;
  145.  
  146.     comlevel=comlevel+1;
  147.     dispt[textp++]=sp;
  148.     textnosave=intext->text[sp].text.text_no;
  149.     i=1;
  150.     len=len-1;
  151.     while ( len>0 ) {
  152.         switch (intext->text[sp+i].text.id){
  153.             case TEXT3C_ID :
  154.             case TEXT5C_ID :
  155.                 if (intext->text[sp+i].text.com_no==textnosave
  156.                             && intext->text[sp+i].text.com_lvl==0){
  157.                     intext->text[sp+i].text.com_lvl=comlevel;
  158.                     parset(intext,sp+i,len,dispt);
  159.                 }
  160.                 break;
  161.         }
  162.         i=i+1;
  163.         len=len-1;
  164.     }
  165.     comlevel=comlevel-1;
  166.     return;
  167. }
  168.  
  169.